package com.wmlive.hhvideo.heihei.mainhome.presenter;

import android.text.TextUtils;

import com.wmlive.hhvideo.common.base.BasePresenter;
import com.wmlive.hhvideo.common.base.BaseView;
import com.wmlive.hhvideo.common.network.HttpConstant;
import com.wmlive.hhvideo.heihei.beans.main.VideoCommentResponse;
import com.wmlive.hhvideo.heihei.beans.splash.InitCatchData;
import com.wmlive.networklib.entity.DCNetObserver;

/**
 * Created by lsq on 6/15/2017.
 * 评论的Presenter
 */

public class CommentPresenter extends BasePresenter<CommentPresenter.ICommentView> {

    private int offset;

    public CommentPresenter(ICommentView view) {
        super(view);
    }

    //评论
    public void comment(final long videoId, String comment, String remindUserId, long replayUserId) {
        String url = InitCatchData.opusCommendOpus();
        if (!TextUtils.isEmpty(url)) {
            executeRequest(HttpConstant.TYPE_FETCH_COMMENT, getHttpApi()
                    .commentVideo(url, videoId, comment, remindUserId, replayUserId))
                    .subscribe(new DCNetObserver<VideoCommentResponse>() {
                        @Override
                        public void onRequestDataReady(int requestCode, String message, VideoCommentResponse response) {
                            if (viewCallback != null) {
                                viewCallback.onCommentOk(response);
                            }
                        }

                        @Override
                        public void onRequestDataError(int requestCode, int serverCode, String message) {
                            if (serverCode == 30005) {//视频被删除了
                                if (null != viewCallback) {
                                    viewCallback.onCommentFailed(message);
                                }
                            } else {
                                onRequestError(HttpConstant.TYPE_FETCH_COMMENT, message);
                            }
                        }
                    });
        } else {
            onRequestUrlError(HttpConstant.TYPE_FETCH_COMMENT);
        }

    }


    public interface ICommentView extends BaseView {
        void onCommentOk(VideoCommentResponse bean);

        void onCommentFailed(String msg);
    }
}
